{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "\n",
    "x_mock=np.array(range(300))\n",
    "x_mock=x_mock.reshape([10,10,3])\n",
    "#三个卷积核\n",
    "w_r_value1=np.array([[1,0,0],[0,1,0],[0,0,1]],dtype=float)\n",
    "w_g_value1=np.array([[1,1,0],[0,1,1],[1,0,1]],dtype=float)\n",
    "w_b_value1=np.array([[2,1,0],[0,1,2],[1,2,0]],dtype=float)\n",
    "\n",
    "w_r_value2=np.array([[1,0,0],[1,0,0],[1,0,0]],dtype=float)\n",
    "w_g_value2=np.array([[0,1,0],[0,1,0],[0,1,0]],dtype=float)\n",
    "w_b_value2=np.array([[0,0,1],[0,0,1],[0,0,1]],dtype=float)\n",
    "\n",
    "w_r_value3=np.array([[1,-1,0],[0,1,-1],[-1,0,1]],dtype=float)\n",
    "w_g_value3=np.array([[1,0,-1],[-1,1,0],[0,-1,1]],dtype=float)\n",
    "w_b_value3=np.array([[1,-2,0],[-2,1,0],[0,-2,1]],dtype=float)\n",
    "\n",
    "kernel1=np.stack([w_r_value1,w_g_value1,w_b_value1],axis=2)\n",
    "kernel2=np.stack([w_r_value2,w_g_value2,w_b_value2],axis=2)\n",
    "kernel3=np.stack([w_r_value3,w_g_value3,w_b_value3],axis=2)\n",
    "\n",
    "kernel=np.stack([kernel1,kernel2,kernel3],axis=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0\t0.0\t0.0\t\n",
      "0.0\t1.0\t0.0\t\n",
      "0.0\t0.0\t1.0\t\n",
      "-------------------\n",
      "1.0\t1.0\t0.0\t\n",
      "0.0\t1.0\t1.0\t\n",
      "1.0\t0.0\t1.0\t\n",
      "-------------------\n",
      "2.0\t1.0\t0.0\t\n",
      "0.0\t1.0\t2.0\t\n",
      "1.0\t2.0\t0.0\t\n",
      "-------------------\n",
      "1.0\t0.0\t0.0\t\n",
      "1.0\t0.0\t0.0\t\n",
      "1.0\t0.0\t0.0\t\n",
      "-------------------\n",
      "0.0\t1.0\t0.0\t\n",
      "0.0\t1.0\t0.0\t\n",
      "0.0\t1.0\t0.0\t\n",
      "-------------------\n",
      "0.0\t0.0\t1.0\t\n",
      "0.0\t0.0\t1.0\t\n",
      "0.0\t0.0\t1.0\t\n",
      "-------------------\n",
      "1.0\t-1.0\t0.0\t\n",
      "0.0\t1.0\t-1.0\t\n",
      "-1.0\t0.0\t1.0\t\n",
      "-------------------\n",
      "1.0\t0.0\t-1.0\t\n",
      "-1.0\t1.0\t0.0\t\n",
      "0.0\t-1.0\t1.0\t\n",
      "-------------------\n",
      "1.0\t-2.0\t0.0\t\n",
      "-2.0\t1.0\t0.0\t\n",
      "0.0\t-2.0\t1.0\t\n",
      "-------------------\n"
     ]
    }
   ],
   "source": [
    "for num in range(3):\n",
    "    for depth in range(3):\n",
    "        for height in range(3):\n",
    "            for width in range(3):\n",
    "                print(kernel[height][width][depth][num],end='\\t')\n",
    "            print('')\n",
    "        print('-------------------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\t3\t6\t9\t12\t15\t18\t21\t24\t27\t\n",
      "30\t33\t36\t39\t42\t45\t48\t51\t54\t57\t\n",
      "60\t63\t66\t69\t72\t75\t78\t81\t84\t87\t\n",
      "90\t93\t96\t99\t102\t105\t108\t111\t114\t117\t\n",
      "120\t123\t126\t129\t132\t135\t138\t141\t144\t147\t\n",
      "150\t153\t156\t159\t162\t165\t168\t171\t174\t177\t\n",
      "180\t183\t186\t189\t192\t195\t198\t201\t204\t207\t\n",
      "210\t213\t216\t219\t222\t225\t228\t231\t234\t237\t\n",
      "240\t243\t246\t249\t252\t255\t258\t261\t264\t267\t\n",
      "270\t273\t276\t279\t282\t285\t288\t291\t294\t297\t\n",
      "-------------------\n",
      "1\t4\t7\t10\t13\t16\t19\t22\t25\t28\t\n",
      "31\t34\t37\t40\t43\t46\t49\t52\t55\t58\t\n",
      "61\t64\t67\t70\t73\t76\t79\t82\t85\t88\t\n",
      "91\t94\t97\t100\t103\t106\t109\t112\t115\t118\t\n",
      "121\t124\t127\t130\t133\t136\t139\t142\t145\t148\t\n",
      "151\t154\t157\t160\t163\t166\t169\t172\t175\t178\t\n",
      "181\t184\t187\t190\t193\t196\t199\t202\t205\t208\t\n",
      "211\t214\t217\t220\t223\t226\t229\t232\t235\t238\t\n",
      "241\t244\t247\t250\t253\t256\t259\t262\t265\t268\t\n",
      "271\t274\t277\t280\t283\t286\t289\t292\t295\t298\t\n",
      "-------------------\n",
      "2\t5\t8\t11\t14\t17\t20\t23\t26\t29\t\n",
      "32\t35\t38\t41\t44\t47\t50\t53\t56\t59\t\n",
      "62\t65\t68\t71\t74\t77\t80\t83\t86\t89\t\n",
      "92\t95\t98\t101\t104\t107\t110\t113\t116\t119\t\n",
      "122\t125\t128\t131\t134\t137\t140\t143\t146\t149\t\n",
      "152\t155\t158\t161\t164\t167\t170\t173\t176\t179\t\n",
      "182\t185\t188\t191\t194\t197\t200\t203\t206\t209\t\n",
      "212\t215\t218\t221\t224\t227\t230\t233\t236\t239\t\n",
      "242\t245\t248\t251\t254\t257\t260\t263\t266\t269\t\n",
      "272\t275\t278\t281\t284\t287\t290\t293\t296\t299\t\n",
      "-------------------\n"
     ]
    }
   ],
   "source": [
    "for depth in range(3):\n",
    "    for height in range(10):\n",
    "        for width in range(10):\n",
    "            print(x_mock[height][width][depth],end='\\t')\n",
    "        print('')\n",
    "    print('-------------------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "output_numpy=np.zeros([8,8,3])\n",
    "for num in range(3):\n",
    "    for height in range(10-2):\n",
    "        for width in range(10-2):\n",
    "            along_depth_sum=0\n",
    "            for depth in range(3):\n",
    "                depth_result=(x_mock[height:height+3,width:width+3,depth]*kernel[depth][num]).sum()\n",
    "                along_depth_sum+=depth_result\n",
    "            output_numpy[height][width][num]=along_depth_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "185.0\t209.0\t233.0\t257.0\t281.0\t305.0\t329.0\t353.0\t \n",
      "425.0\t449.0\t473.0\t497.0\t521.0\t545.0\t569.0\t593.0\t \n",
      "665.0\t689.0\t713.0\t737.0\t761.0\t785.0\t809.0\t833.0\t \n",
      "905.0\t929.0\t953.0\t977.0\t1001.0\t1025.0\t1049.0\t1073.0\t \n",
      "1145.0\t1169.0\t1193.0\t1217.0\t1241.0\t1265.0\t1289.0\t1313.0\t \n",
      "1385.0\t1409.0\t1433.0\t1457.0\t1481.0\t1505.0\t1529.0\t1553.0\t \n",
      "1625.0\t1649.0\t1673.0\t1697.0\t1721.0\t1745.0\t1769.0\t1793.0\t \n",
      "1865.0\t1889.0\t1913.0\t1937.0\t1961.0\t1985.0\t2009.0\t2033.0\t \n",
      "----------\n",
      "208.0\t229.0\t250.0\t271.0\t292.0\t313.0\t334.0\t355.0\t \n",
      "418.0\t439.0\t460.0\t481.0\t502.0\t523.0\t544.0\t565.0\t \n",
      "628.0\t649.0\t670.0\t691.0\t712.0\t733.0\t754.0\t775.0\t \n",
      "838.0\t859.0\t880.0\t901.0\t922.0\t943.0\t964.0\t985.0\t \n",
      "1048.0\t1069.0\t1090.0\t1111.0\t1132.0\t1153.0\t1174.0\t1195.0\t \n",
      "1258.0\t1279.0\t1300.0\t1321.0\t1342.0\t1363.0\t1384.0\t1405.0\t \n",
      "1468.0\t1489.0\t1510.0\t1531.0\t1552.0\t1573.0\t1594.0\t1615.0\t \n",
      "1678.0\t1699.0\t1720.0\t1741.0\t1762.0\t1783.0\t1804.0\t1825.0\t \n",
      "----------\n",
      "450.0\t477.0\t504.0\t531.0\t558.0\t585.0\t612.0\t639.0\t \n",
      "720.0\t747.0\t774.0\t801.0\t828.0\t855.0\t882.0\t909.0\t \n",
      "990.0\t1017.0\t1044.0\t1071.0\t1098.0\t1125.0\t1152.0\t1179.0\t \n",
      "1260.0\t1287.0\t1314.0\t1341.0\t1368.0\t1395.0\t1422.0\t1449.0\t \n",
      "1530.0\t1557.0\t1584.0\t1611.0\t1638.0\t1665.0\t1692.0\t1719.0\t \n",
      "1800.0\t1827.0\t1854.0\t1881.0\t1908.0\t1935.0\t1962.0\t1989.0\t \n",
      "2070.0\t2097.0\t2124.0\t2151.0\t2178.0\t2205.0\t2232.0\t2259.0\t \n",
      "2340.0\t2367.0\t2394.0\t2421.0\t2448.0\t2475.0\t2502.0\t2529.0\t \n",
      "----------\n"
     ]
    }
   ],
   "source": [
    "for num in range(3):\n",
    "    for height in range(8):\n",
    "        for width in range(8):\n",
    "            print(output_numpy[height][width][num],end='\\t')\n",
    "        print(' ')\n",
    "    print('----------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
